package com.rbac.modules.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rbac.common.api.R;
import com.rbac.modules.system.dto.DeptDTO;
import com.rbac.modules.system.dto.DeptQuery;
import com.rbac.modules.system.entity.SysDept;
import com.rbac.modules.system.service.SysDeptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "部门管理")
@RestController
@RequestMapping("/system/dept")
@RequiredArgsConstructor
public class SysDeptController {

    private final SysDeptService deptService;

    @Operation(summary = "分页查询部门")
    @GetMapping("/page")
    public R<Page<SysDept>> page(DeptQuery query) {
        return R.ok(deptService.page(query));
    }

    @Operation(summary = "获取部门树")
    @GetMapping("/tree")
    public R<List<SysDept>> tree() {
        return R.ok(deptService.tree());
    }

    @Operation(summary = "创建部门")
    @PostMapping
    public R<Void> create(@RequestBody DeptDTO deptDTO) {
        deptService.create(deptDTO);
        return R.ok();
    }

    @Operation(summary = "更新部门")
    @PutMapping
    public R<Void> update(@RequestBody DeptDTO deptDTO) {
        deptService.update(deptDTO);
        return R.ok();
    }

    @Operation(summary = "删除部门")
    @DeleteMapping("/{ids}")
    public R<Void> delete(@PathVariable Long[] ids) {
        deptService.delete(ids);
        return R.ok();
    }
} 